<?php
//积分功能
//$Id: score.php 9 2009-04-26 06:35:12Z bole.Chen $
uses('controller');

/*
1.付款成功后加积分，积分=零售价-代销价
2.管理员改为未付款后减积分
3.来自哪个用户的点击？loopo_uid，是否要保存到支付返回结果url中？有没有更好的办法？
4.判断用户是否代销商
*/

class scoreController extends Controller {

    var $uid;

    function __construct() {
        parent::__construct();
    }

    //按 id 查询用户积分
    function getScoreFromId($uid) {
    }

    //更新积分
    //$types: 1 购物 2 代销
    function updateScore($uid, $iid, $types, $score, $memo='') {
        $data['uid']        = intval($uid);
        $data['iid']        = intval($iid);
        $data['types']      = intval($types);
        $data['score']      = intval($score);
        $data['memo']       = trim($memo);

        if ($data['memo'] == '') {
            switch ($data['types']) {
                case 1:
                    $data['memo'] = "$iid 号订单购物返点";
                    break;
                case 2:
                    $data['memo'] = "$iid 号订单代销返点";
                    break;
                default:
                    $data['memo'] = "$iid 号订单返点";
            }
        }

        $data['code']['update'] = $this->model->update($data);

        return $data;
    }

    function delByiid($iid) {
        $data['code']['del'] = $this->model->delByiid(intval($iid));
        return $data;
    }

    function setUid($uid) {
        $this->uid = $uid;
        return true;
    }
}
?>
